class LinkNode:
    """
    实现单向列表
    """
    def __init__(self,data=None,next=None):
        self.data = data
        self.next = next
        self._it = None

    def __iter__(self):
        self._it = self
        return self

    def __next__(self):
        if self._it is None:
            raise StopIteration
        result = self._it.data
        self._it = self._it.next
        return result

def list2linknode(ls): #tuple,list
    """
    将列表转换为链表
    """
    head = LinkNode()
    current = head
    for i,v in enumerate(ls):
        if i==0:
            current.data = v
        else:
            current.next = LinkNode(v)
            current = current.next
    return head

def foreach_linknode(node):
    """
    生成器
    """
    while node is not None:
        yield node.data
        node = node.next

root = list2linknode([3,4,5,6,7])
d = {
    "a":1,
    "b":2,
    "c":3
}

for i in root:
    print(i)


#iterator = iter(root) #root.__iter__()
#try:
#    while True:
#        v = next(iterator)
#        print(v)
#except StopIteration:
#    pass
